package com.rr.sort;

import java.util.Arrays;

/**
 * @author RR
 * @date 2022/10/2 0:12
 */
public class BubbleSort {
    public static void main(String[] args) {
        int[] array = new int[]{5, 10, 7, 6, 3, 2, 8};
        bubbleSort(array);
        System.out.println(Arrays.toString(array));
    }

    public static void bubbleSort(int[] array) {
        int length = array.length;
        for (int i = 1; i < length; i++) {
            for (int j = 0; j < length - i; j++) {
                if (array[j] > array[j + 1]) {
                    int temp = array[j];
                    array[j] = array[j + 1];
                    array[j + 1] = temp;
                }
            }
        }
    }
}
